package day0414;

public class Test9 {
    public static String customTrim(String str) {
        int start = 0;
        int end = str.length() - 1;
        while (start <= end && isSpace(str.charAt(start))) {
            start++;
        }
        while (end >= start && isSpace(str.charAt(end))) {
            end--;
        }
        return str.substring(start, end + 1);
    }

    public static boolean isSpace(char a) {
        return a == ' ' ;
    }

    public static void main(String[] args) {
        String str = "   1   ";
        String trimmedStr = customTrim(str);
        System.out.println("原字符串: \"" + str + "\"");
        System.out.println("去除首尾空白后的字符串: \"" + trimmedStr + "\"");
    }
}